home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-01-31 | 5.6 KB | 153 lines | [TEXT/R*ch] |
- // ===========================================================================
- // File: CExternalCmdKeyAttachment.cp
- // Version: 1.0.1 - Jan 31, 1997
- // Author: Mike Shields (mshields@inconnect.com)
- //
- // Copyright ©1996 Mike Shields. All rights reserved.
- // I hereby grant users of CExternalCmdKeyAttachment permission to use it (or any modified
- // version of it) in applications (or any other type of Macintosh software
- // like extensions -- freeware, shareware, commercial, or other) for free,
- // subject to the terms that:
- //
- // (1) This agreement is non-exclusive.
- //
- // (2) I, Mike Shields, retain the copyright to the original source code.
- //
- // These two items are the only required conditions for use. However, I do have
- // an additional request. Note, however, that this is only a request, and
- // that it is not a required condition for use of this code.
- //
- // (1) That I be given credit for CExternalCmdKeyAttachment code in the copyrights or
- // acknowledgements section of your manual or other appropriate documentation.
- //
- //
- // I would like to repeat that this last item is only a request. You are prefectly
- // free to choose not to do any or all of them.
- //
- // This source code is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- // ===========================================================================
- // CExternalCmdKeyAttachment.h <- double-click + Command-D to see class declaration
- //
- // Class which handles drawing and responding to command keys when it is attached
- // to a button
-
- #include "CExternalCmdKeyAttachment.h"
- #include <LStream.h>
-
- //----------------------------------------------------------------------------------------
- // CExternalCmdKeyAttachment::CreateFromStream
- //----------------------------------------------------------------------------------------
- CExternalCmdKeyAttachment* CExternalCmdKeyAttachment::CreateFromStream(LStream *inStream)
- {
- return new CExternalCmdKeyAttachment(inStream);
- }
-
- //----------------------------------------------------------------------------------------
- // CExternalCmdKeyAttachment::CExternalCmdKeyAttachment
- //----------------------------------------------------------------------------------------
- CExternalCmdKeyAttachment::CExternalCmdKeyAttachment()
- : mCommandKeyLocation(position_Right)
- {
- mCommandKeyOffset.h = mCommandKeyOffset.v = 0;
- }
-
- //----------------------------------------------------------------------------------------
- // CExternalCmdKeyAttachment::CExternalCmdKeyAttachment
- //----------------------------------------------------------------------------------------
- CExternalCmdKeyAttachment::CExternalCmdKeyAttachment(LStream *inStream)
- : CCmdKeyAttachment(inStream)
- {
- inStream->ReadData(&mCommandKeyLocation, sizeof(Int16));
- inStream->ReadData(&mCommandKeyOffset, sizeof(Point));
- }
-
- //----------------------------------------------------------------------------------------
- // CExternalCmdKeyAttachment::~CExternalCmdKeyAttachment
- //----------------------------------------------------------------------------------------
- CExternalCmdKeyAttachment::~CExternalCmdKeyAttachment()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CExternalCmdKeyAttachment::EnableCommandKey
- //----------------------------------------------------------------------------------------
- // All this finction has to do is to draw the command key. We don't do any checking of
- // if the command key is already down because since we draw outside of the controls
- // frame, we won't update correctly if the control's frame is not invalidated but
- // the area we draw in is.
- void CExternalCmdKeyAttachment::EnableCommandKey(Boolean inCmdDown)
- {
- DrawCommandKey(inCmdDown);
- }
-
- //----------------------------------------------------------------------------------------
- // CExternalCmdKeyAttachment::GetCommandKeyPosition
- //----------------------------------------------------------------------------------------
- // This determines where to place the command key based on the location and offset
- // the programmer specified.
- void CExternalCmdKeyAttachment::GetCommandKeyPosition(Point& outPosition)
- {
- Rect frame;
- mMyControl->CalcLocalFrameRect(frame);
-
- switch ( mCommandKeyLocation )
- {
- case position_Top:
- outPosition.h = frame.left + mCommandKeyOffset.h;
- outPosition.v = frame.top - mCommandKeyOffset.v;
- break;
-
- case position_Left:
- outPosition.h = frame.left - mCommandKeyOffset.h;
- outPosition.v = frame.top + mCommandKeyOffset.v;
- break;
-
- case position_Bottom:
- outPosition.h = frame.left + mCommandKeyOffset.h;
- outPosition.v = frame.bottom + mCommandKeyOffset.v;
- break;
-
- case position_Right:
- // That's right we're falling on through
- default:
- outPosition.h = frame.right + mCommandKeyOffset.h;
- outPosition.v = frame.top + mCommandKeyOffset.v;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CExternalCmdKeyAttachment::DrawCommandKey
- //----------------------------------------------------------------------------------------
- void CExternalCmdKeyAttachment::DrawCommandKey(Boolean inVisible)
- {
- Point pos;
- char str[2] = { char_Propeller, mCommandKey };
-
- if ( mMyControl->FocusExposed() )
- {
- StColorPenState colorPenState;
- StTextState textState;
-
- ::TextFont(systemFont);
- ::TextSize(12);
- ::TextFace(0);
-
- if ( inVisible == false )
- {
- RGBColor backColor;
- ::GetBackColor(&backColor);
- ::RGBForeColor(&backColor);
- }
-
- this->GetCommandKeyPosition(pos);
-
- ::MoveTo(pos.h, pos.v);
- ::UpperText(&str[1], 1);
- ::DrawText(str, 0, sizeof(str));
- }
- }
-
-
-